package com.datastructure.tree.rtree;

public class Point2D {

	public final static Quadrant[] quadArr = Quadrant.values();
	
	private double x;
	
	private double y;
	
	public double getX() {
		return x;
	}

	public void setX(double x) {
		this.x = x;
	}

	public double getY() {
		return y;
	}

	public void setY(double y) {
		this.y = y;
	}

	
	public Point2D(double x, double y){
		
		this.x = x;
		this.y = y;
	}
	
	public Quadrant getQuad(Point2D other){		
	
		
		if(Double.isNaN(other.x)||Double.isNaN(other.y))
			return null;
		
		if(Double.isInfinite(other.x)||Double.isInfinite(other.y))
			return null;
		
	//	z = 3x + y
		double x1 = 0;
		double y1 = 0;
		int z1 = 0;
		
		x1 = Math.signum(other.x - this.x);
		y1 = Math.signum(other.y - this.y);
		// [-4,4] + 4
		z1 = (int)(3*x1 + y1)+4;		

		return Quadrant.values()[z1];
		
	}

}
 
// enum Quadrant{NULL,CENTER,NE,N,NW,W,SW,S,SE,E};
	enum Quadrant{SW,W,NW,S,CENTER,N,SE,E,NE,NULL};

//mapping int to enum
/*
 * class EnumValues<E extends Enum<E>>
{
    E[] values;

    public EnumValues( Class<E> enumType )
    {
        values = enumType.getEnumConstants();
    }
    public E intToValue( int i ) {
        return values[i];
    }
}*/

/*
enum MyEnum { INIT, WORKING, FINAL, COMPLETE };

final static class EnumMap {
    // Map for int <-> enum links
    static Map<Integer, MyEnum> intMap =
                new HashMap<Integer, MyEnum>(4);

    // Static initialisation for the Map
    static {
        for (MyEnum e : MyEnum.values()) {
            intMap.put(e.ordinal(), e);
        }
    }

    // This is the function you want
    // Returns null if key value not found.
    public static MyEnum intValue(int key) {
        return intMap.get(key);
    }
} // end class EnumMap
*/

